Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

usb

Package Overview
Dependencies
Maintainers
3
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

usb

Library to access USB devices

  • 2.14.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
136K
increased by13.68%
Maintainers
3
Weekly downloads
 
Created

What is usb?

The 'usb' npm package provides a way to interact with USB devices in Node.js. It allows you to list, read from, and write to USB devices, making it useful for applications that need to communicate with hardware peripherals.

What are usb's main functionalities?

Listing USB Devices

This feature allows you to list all USB devices connected to the system. The code sample demonstrates how to use the 'usb' package to retrieve and print the list of connected USB devices.

const usb = require('usb');
const devices = usb.getDeviceList();
console.log(devices);

Opening a USB Device

This feature allows you to open a connection to a specific USB device using its vendor and product IDs. The code sample shows how to find and open a USB device.

const usb = require('usb');
const device = usb.findByIds(vendorId, productId);
device.open();

Reading from a USB Device

This feature allows you to read data from a USB device. The code sample demonstrates how to open a device, access its endpoint, and read data from it.

const usb = require('usb');
const device = usb.findByIds(vendorId, productId);
device.open();
const endpoint = device.interfaces[0].endpoints[0];
endpoint.transfer(64, (error, data) => {
  if (error) {
    console.error(error);
  } else {
    console.log(data);
  }
});

Writing to a USB Device

This feature allows you to write data to a USB device. The code sample shows how to open a device, access its endpoint, and send data to it.

const usb = require('usb');
const device = usb.findByIds(vendorId, productId);
device.open();
const endpoint = device.interfaces[0].endpoints[1];
const data = Buffer.from('Hello USB');
endpoint.transfer(data, (error) => {
  if (error) {
    console.error(error);
  } else {
    console.log('Data sent');
  }
});

Other packages similar to usb

Keywords

FAQs

Package last updated on 15 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc